﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IDAL;
using System.Data.SqlClient;
using SQLServerDAL;
using System.Data;

namespace DAL
{
  public class QQRelationDal : IQQRelationDAL
  {
    string strSQL = "";
    public int AddQQRelation(Model.QQRelation relation)
    {
      strSQL = "insert into QQRelation values(@MainQQ,@QQ,@CreateTime)";
      SqlParameter[] param = new SqlParameter[] { 
        new SqlParameter("@MainQQ",relation.MainQQ),
        new SqlParameter("@QQ",relation.QQ),
        new SqlParameter("@CreateTime",relation.CreateTime)
      };
      return SQLHelper.ExecuteSql(strSQL, param);
    }
    public int DeleteQQRelation(string userId)
    {
      strSQL = "delete QQRelation where QQMappID=@QQMappID";
      SqlParameter[] paras = new SqlParameter[] { 
        new SqlParameter("@QQMappID",userId)
      };
      return SQLHelper.ExecuteSql(strSQL, paras);
    }
    public System.Data.DataTable GetAllRelations()
    {
      strSQL = "select * from QQRelation";
      return SQLHelper.ExecuteDt(strSQL);
    }
    public int UpdateQQRelation(Model.QQRelation relation)
    {
      strSQL = "update QQRelation set MainQQ=@MainQQ,QQ=@QQ,CreateTime=@CreateTime where QQMappID=@QQMappID";
      SqlParameter[] paras = new SqlParameter[] { 
        new SqlParameter("@MainQQ",relation.MainQQ),
        new SqlParameter("@QQ",relation.QQ),
        new SqlParameter("@CreateTime",relation.CreateTime),
        new SqlParameter("@QQMappID",relation.QQMappID)
      };
      return SQLHelper.ExecuteSql(strSQL, paras);
    }
    //public int UpdateQQRelation(string qq)
    //{
    //  strSQL = "update QQRelation set MainQQ=@MainQQ,QQ=@QQ,CreateTime=@CreateTime where QQMappID=@QQMappID";
    //  SqlParameter[] paras = new SqlParameter[] { 
    //    new SqlParameter("@MainQQ",relation.MainQQ),
    //    new SqlParameter("@QQ",relation.QQ),
    //    new SqlParameter("@CreateTime",relation.CreateTime),
    //  };
    //  return SQLHelper.ExecuteSql(strSQL, paras);
    //}

    public int GetTotal()
    {
      strSQL = "select count(*) from QQRelation";
      return SQLHelper.ExecuteScalar(strSQL);
      // DataSet ds = arti.getPageDatas(AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "Article");
    }
    public DataSet getDataByPage(int currentPage, int pageSize)
    {
      using (SqlConnection conn = new SqlConnection(SQLHelper.GetSqlConnection()))
      {
        conn.Open();
        using (SqlCommand cmd = conn.CreateCommand())
        {
          string strSQL = "select * from QQRelation";

          SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn);
          DataSet ds = new DataSet();

          adapter.Fill(ds, currentPage, pageSize, "viewspotTable");

          return ds;
        }
      }
    }
    public DataTable isSameQQ(string mainQQ, string qq)
    {
      strSQL = "select * from QQRelation where MainQQ=@MainQQ and QQ=@QQ";
      SqlParameter[] paras = new SqlParameter[] { 
        new SqlParameter("@MainQQ",mainQQ),
        new SqlParameter("@QQ",qq)
      };
      DataTable dt = SQLHelper.ExecuteDt(strSQL, paras);
      return dt;
    }

    public DataTable getSameQQ(string qq)
    {
      strSQL = "select * from QQRelation where MainQQ like @QQ or QQ like @QQ";
      SqlParameter[] paras = new SqlParameter[] { 
            new SqlParameter("@QQ",qq)
      };
      return SQLHelper.ExecuteDt(strSQL, paras);

    }
 

  }
}
